package example.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import example.dao.UsersDao;
import example.entity.Users;
import example.service.UsersService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Users)表服务实现类
 *
 * @author makejava
 * @since 2022-05-05 11:23:35
 */
@Service("usersService")
public  class UsersServicceImpl implements UsersService {
    @Resource
    private UsersDao usersDao;


    @Override
    public Users queryById(Integer uid){
        Users users = usersDao.queryById(uid);
      return  users;}

    @Override
    public List<Users> queryAll(Users users) {
        return null;
    }

    @Override
    public List<Users> findAll() {
        return usersDao.findAll();
    }


    /**
 * 查询多条数据
 *
 * @param offset 查询起始位置
 * @param limit  查询条数
 * @return 对象列表
 */
@Override
public  List<Users> queryAllByLimit(int offset,int limit){
    return this.usersDao.queryAllByLimit(offset,limit);
}

@Override
public PageInfo<Users> queryAllByPage(Users users,Integer pageNum,Integer pageSize){
    PageHelper.startPage(pageNum,pageSize);
    List<Users> userList = usersDao.queryAll(users);
    PageInfo<Users> userListPage = new PageInfo<>(userList);
    return userListPage;
}

/**
 * 新增数据
 *
 * @param users 实例对象
 */
@Override
public Users insert(Users users){
    this.usersDao.insert(users);
    return  users;

}
@Override
public  Users update(Users users){
    this.usersDao.update(users);
    return users;

}
    /**
     * 通过主键删除数据
     *
     * @param uid 主键
     * @return 是否成功
     */

    @Override
    public  boolean deleteById(Integer uid){
        boolean flag = this.usersDao.deleteById(uid)>0;
    return  flag;
    }
}


